package com.wyiot.pet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wyiot.core.enums.OrderStatusEnum;
import com.wyiot.pet.model.entity.OrderDO;
import com.wyiot.pet.model.entity.WayBillDO;
import com.wyiot.pet.model.vo.OrderDetailVO;
import com.wyiot.pet.model.vo.WayBillPetVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<OrderDO> {
    /**
     * 查询订单所携带的宠物信息
     */
    List<WayBillPetVO> selectWayBillPetByOrderId(@Param("id") Long orderId);

    /**
     * 改变订单状态
     */
    @Update("update pet_order set order_state = #{state} where order_id = #{id}")
    void changeOrderStateByOrderId(@Param("id") Long orderId, @Param("state") OrderStatusEnum statusEnum);

    /**
     * 根据订单id查询对应运单信息
     */
    @Select("select way_bill_id, box_id , way_bill_number ,transportation_type from waybill where order_id = #{id}")
    List<WayBillDO> selectWayBillByOrderId(@Param("id") Long orderId);


    /**
     * 查询我寄的订单列表
     */
    Page<OrderDetailVO> selectOrdersByUserIdAndCode(Page page, @Param("uid") Long userId,@Param("state")Integer state );

    /**
     * 查询我收的订单列表
     */
    Page<OrderDetailVO> selectOrdersByPhoneAndState(Page page, @Param("phone") String phone, @Param("state") Integer state );

    /**
     * 查询其他类型订单
     */
    @Select("SELECT * FROM pet_order where user_id = #{uid} and order_state in (4,5,6,7)")
    Page<OrderDetailVO> selectOtherOrder(Page page, @Param("uid") Long userId);

    /**
     * 根据订单或者运单号查询订单
     */
    @Select("select * from pet_order where order_number= #{number} ")
    OrderDO selectOrderByOrderNumber(@Param("number")String number );

    OrderDO selectOrderByWaybillNumber(@Param("number")String number);



}
